package com.my.hzb.user.ctrl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.my.hzb.common.bean.ResultBean;
import com.my.hzb.common.util.CommonUtil;
import com.my.hzb.entiy.Menu;
import com.my.hzb.entiy.MenuRole;
import com.my.hzb.user.service.MenuRoleService;
import com.my.hzb.user.service.MenuService;

@Controller
@RequestMapping("menu")
public class MenuCtrl {

	@Autowired
	private MenuService menuService;
	@Autowired
	private MenuRoleService menuRoleService;
	
	@RequestMapping("addMenu")
	public void addMenu(Menu menu){
		menuService.add(menu);
	}
	@RequestMapping("getMenuList")
	@ResponseBody
	public ResultBean getMenuList(Menu menu){
		ResultBean result = new ResultBean(ResultBean.RETURN_ERROR_CODE,ResultBean.RETURN_ERROR_MSG);
		List<Menu> list = menuService.find(menu);
		return result;
	}
	
	@RequestMapping("addMenuRole")
	@ResponseBody
	public ResultBean addMenuRole(MenuRole menuRole,String meuns){
		ResultBean result = new ResultBean(ResultBean.RETURN_ERROR_CODE,ResultBean.RETURN_ERROR_MSG);
		if(!CommonUtil.isNull(meuns)){
			String[] strId = meuns.split(",");
			for(String id:strId){
				Menu menu = menuService.getOne(Integer.parseInt(id));
				if(null!=menu){
					menuRole.setMenuId(menu.getId());
					menuRoleService.add(menuRole);
				}
			}
		}
		return result;
	}
}
